<template>
	<view>
		<!-- <nav-bar title="我的信息"></nav-bar> -->
		<scroll-view scroll-y :style="{ height: mainHeight }">
		
		<view class="message" style="margin-top: 50rpx;">
			<view class="list" v-for="(item, index) in topList" :key="index">
				<view class="left">{{ item.title }}</view>
				<view class="right">
					<img :src="avatar" alt="" class="photo" v-if="item.isImg">
					<view v-if="!item.isImg && item.text" style="margin-right: 30rpx;">{{ item.text }}</view>
					<view class="icon" @click="toNext(item)">
						<u-icon name="arrow-right" color="#666666" size="18"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<view class="message">
			<view class="list" v-for="(item, index) in bottomList" :key="index">
				<view class="left">{{ item.title }}</view>
				<view class="right">
					<view v-if="item.text" style="margin-right: 30rpx;">{{ item.text }}</view>
				</view>
			</view>
		</view>
		</scroll-view>
	</view>
</template>

<script>
	import NavBar from '@/components/nav-bar/index.vue'
	import tabIndex from '../../components/statis/tab-index.vue'
  // import { editUserData, editManageData1,editManageData2 } from "@/api/system/mine"
  import { getUserData,getManageData1,getManageData2 } from '@/api/system/mine'
import avatar from 'uview-ui/libs/config/props/avatar'

	export default {
		name: 'member',
		components: {
			NavBar,
			tabIndex
		},
		data() {
			return {
				mainHeight: '',
				topList: [
          // {
					// 	title: '头像',
					// 	isImg: true,
					// 	path: '/subPages/mine/uploadPhoto'
					// },
					// {
					// 	title: '姓名',
					// 	text: 'name',
					// 	path: '/subPages/mine/editName'
					// },
					// {
					// 	title: '电话',
					// 	text: 'phone'
					// }
				],
				bottomList: [
         
				],
        roles:'',
        userId:'',
        avatar:''
			}
		},
		created() {
			this.mainHeight = this.$store.getters.heightData.noTabMainHeight + 'px'
      this.roles = uni.getStorageSync('roles')
      this.userId = uni.getStorageSync('userId')
		this.isMaster()
			// this.getData()
		},
    onLoad(options) {
     
        // this.getDetail(options.id)
      
    },
		methods: {
      isMaster() {
			if(this.roles === 103) {
        this.topList = [
          {
						title: '头像',
						isImg: true,
						path: '/subPages/mine/uploadPhoto'
					},
					{
						title: '姓名',
						text: 'name',
						path: '/subPages/mine/editName'
					},
					{
						title: '电话',
						text: 'phoneNumber'
					}
        ]
        this.bottomList = [
					{
						title: '门店',
						text: 'belongStoreName'
					}
					]
				this.getUserData()
			}
			if(this.roles === 100) {
				this.topList = [
					{
						title: '姓名',
						text: 'userName',
						path: '/subPages/mine/editName'
					},
					{
						title: '电话',
						text: 'phoneNumber'
					}
					]
        this.bottomList = [
                   {
						title: '门店',
						text: 'storeName'
					},
        ]
        this.getManageData1()
			}
			if(this.roles === 101) {
        this.topList = [
					{
						title: '姓名',
						text: 'userName',
						path: '/subPages/mine/editName'
					},
					{
						title: '电话',
						text: 'phoneNumber'
					}
        ]
        this.bottomList = [
           {
						title: '门店',
						text: 'storeName'
					},
        ]
				this.getManageData2()
			}
		},
		getUserData() {
			getUserData({ userId: this.userId }).then((res) => {
				// this.userData = res.data
        this.avatar = res.data.avatar
        this.topList.forEach((item) => {
					item.text = res.data[item.text]
				})
				this.bottomList.forEach((item) => {
					item.text = res.data[item.text]
				})
			})
		},
		getManageData1() {
			getManageData1().then((res) => {
				// this.userData = res.data
        this.topList.forEach((item) => {
					item.text = res.data[item.text]
				})
				this.bottomList.forEach((item) => {
					item.text = res.data[item.text]
				})
			})
		},
		getManageData2() {
			getManageData2().then((res) => {
				// this.userData = res.data
        this.topList.forEach((item) => {
					item.text = res.data[item.text]
				})
				this.bottomList.forEach((item) => {
					item.text = res.data[item.text]
				})
			})
		},
			tabClick(item) {
			},
			handelClick(item, index) {
				this.activeIndex = index
			},
			getData() {
				const form = {
					name: '曹静',
					phone: '18771319801',
					address: '金牛湖店'
				}
				this.topList.forEach((item) => {
					item.text = form[item.text]
				})
				this.bottomList.forEach((item) => {
					item.text = form[item.text]
				})
			},
			toNext(item) {
				if (item.path) {
					uni.navigateTo({
						url: item.path
					})
				}
			},
      getDetail(id) {
       if(this.roles === 100) {
        editManageData1({ id:id }).then((res) => {

})
       }
       if(this.roles === 101) {
        editManageData2({ id:id }).then((res) => {

})
       }
       if(this.roles === 103) {
        editUserData({ userId:this.userId }).then((res) => {

})
       }
      }

			// handelClick(item) {
			//   uni.navigateTo({
			//     url: `/subPages/order/${item}`,
			//   })
			// }

		}

	}
</script>

<style lang="scss" scoped>
	.icon {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.message {
		margin-top: 50rpx;
		background-color: #fff;
		margin-bottom: 20rpx;

		.list {
			display: flex;
			justify-content: space-between;
			border-bottom: 1rpx solid #f0f3f5;
			padding: 15rpx 33rpx 18rpx 25rpx;

			.left {
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 40rpx;
				font-weight: 400;
				color: rgba(0, 0, 0, 1);
			}

			.right {
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 36rpx;
				font-weight: 400;
				line-height: 44px;
				color: rgba(128, 128, 128, 1);

				.photo {
					width: 144rpx;
					height: 144rpx;
					border-radius: 50%;
					margin-right: 10rpx;
				}

			}
		}
	}
</style>